import 'package:flutter/material.dart';
import 'package:shenling_logistics/pages/login/index.dart';
import 'package:shenling_logistics/pages/setting/index.dart';
import 'package:shenling_logistics/pages/tabBar/index.dart';
import 'package:shenling_logistics/utils/token.dart';
// import 'package:shenling_logistics/pages/login/index.dart';
// import 'package:shenling_logistics/pages/mine/index.dart';
// import 'package:shenling_logistics/pages/tabBar/index.dart';

void main() {
  runApp(
    MaterialApp(
      // home: LoginPage(),
      routes: {
        '/': (context) => TabBarPage(),
        '/login': (context) => LoginPage(),
      },
      // 路由全局拦截
      onGenerateRoute: (settings) {
        // 同步获取token
        final token = TokenManager().getToken() ?? '';
        // 如果token不存在，并且访问的页面不是登录页，则跳转到登录页
        if (token.isEmpty && settings.name != '/login') {
          // 跳转到登录页
          return MaterialPageRoute(builder: (context) => LoginPage());
        }

        // 跳转到系统设置页面
        if (settings.name == '/setting') {
          return MaterialPageRoute(builder: (context) => SystemSettingPage());
        }

        return null;
      },
    ),
  );
}
